package nl.hanze.designpatterns.DAO.impl.db;

import nl.hanze.designpatterns.DAO.LoginCredentialDAO;
import nl.hanze.designpatterns.Domain.LoginCredential;

import java.sql.SQLException;
import java.util.Iterator;

/**
 *
 * Created by Aron on 25-9-2014.
 */
public class LoginCredentialDAOImpl extends BaseDAOImpl implements LoginCredentialDAO {
    @Override
    public boolean isValid(LoginCredential logincredential) {
        System.out.println("<BaseDAOImpl>[isValid]credential "+logincredential);
        Iterator<LoginCredential> iterator = null;
        try {
            iterator = executor.getIterator(LoginCredential.class, "SELECT * FROM LoginCredential");
        } catch (SQLException e) {
            //return false;
            e.printStackTrace();
        }
        while (iterator.hasNext()){
            LoginCredential loginCredential = iterator.next();
            System.out.println(loginCredential);
            if (loginCredential.toString().equals(logincredential.toString())) {
                return true;
            }
        }
        return false;
    }
}
